/******************************************************************************
 * Epigraph compiler                                                          *
 * Copyright © 2011 Grigorev Svyatoslav                                       *
 *                                                                            *
 * This program is free software: you can redistribute it and/or modify       *
 *     it under the terms of the GNU General Public License as published by   *
 *     the Free Software Foundation, either version 3 of the License, or      *
 *     (at your option) any later version.                                    *
 *                                                                            *
 *     This program is distributed in the hope that it will be useful,        *
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *     GNU General Public License for more details.                           *
 *                                                                            *
 *     You should have received a copy of the GNU General Public License      *
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ******************************************************************************/

package epg;

// Драйвер исходного текста

import java.io.*;

class Text {

	static final int TABSIZE = 3;
	static final char chSPACE = ' ';    // Пробел
	static final char chTAB = '\t';   // Табуляция
	static final char chEOL = '\n';   // Конец строки
	static final char chEOT = '\0';   // Конец текста

	static boolean Ok = false;
	static String Message = "Файл не открыт";
	static int Ch = chEOT;

	private static InputStream f;

	static void NextCh() {
		try {
			if ((Ch = f.read()) == -1)
				Ch = chEOT;
			else if (Ch == '\n') {
				System.out.println();
				Location.Line++;
				Location.Pos = 0;
				Ch = chEOL;
			} else if (Ch == '\r')
				NextCh();
			else if (Ch != '\t') {
				System.out.write(Ch);
				Location.Pos++;
			} else
				do
					System.out.print(' ');
				while (++Location.Pos % TABSIZE != 0);
		} catch (IOException e) {
		}
		;
	}

	static void Reset() {
		if (Location.Path == null) {
			System.out.println(
				"Формат вызова:\n   O <входной файл>");
			run.Close();
		} else
			try {
				f = new FileInputStream(Location.Path);
				Ok = true;
				Message = "Ok";
				Location.Pos = 0;
				Location.Line = 1;
				NextCh();
			} catch (IOException e) {
				Ok = false;
				Message = "Входной файл не найден";
			}
	}

	static void Close() {
		try {
			f.close();
		} catch (IOException e) {
		}
		;
	}

}
